<template>
	<view class="list">
		<view class="article" @click="showArticlePage(key)" v-for="(item,key) in articles" :key="key">
			<image :src="item.thumb" mode="aspectFill" class="article-image"></image>
			<view class="article-detail">
				<view class="article-title">{{item.title}}</view>
				<view class="article-content">{{item.introduction}}</view>
				<view class="label-row">
					<view class="label grey" v-bind:class="colors[index]" v-for="(label,index) in item.labels" :key="index">{{label}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				articles:[],
				colors:["green","amber","orange","green","amber","orange"],
			};
		},
		onLoad:function(e){
			this.getArticles(e.keyword);
		},
		methods:{
			getArticles:function(keyword){
				var that=this;
				that.ajax("/article/sort",{
					keyword:keyword,
				},function(res){
					that.articles=res.data.data;
				});
			},
			showArticlePage:function(index){
				this.ajax("/article/click",{id:this.articles[index].id});
				uni.navigateTo({
					url:"/pages/article/content/content?url="+encodeURI(this.articles[index].url),
				})
			}
		}
	}
</script>

<style>
	.list{
		margin-top: 32upx;
		background: #ffffff;
		box-shadow:0upx 2upx 22upx 0upx rgba(43,159,133,0.14);
		padding:24upx;
	}
	.green {
		background: #45AA8C;
	}
	
	.amber {
		background: #EBBA80;
	}
	
	.orange {
		background: #FF7465;
	}
	
	.article {
		background: #FFFFFF;
		margin-top: 35upx;
		box-shadow:0upx 2upx 22upx 0upx rgba(43,159,133,0.14);
		border-radius:18upx;
	}
	
	.article-image {
		width: 100%;
		height: 352upx;
		border-top-right-radius: 18upx;
		border-top-left-radius: 18upx;
	}
	
	.article-detail {
		padding: 18upx 22upx;
	}
	
	.article-title {
		color:#4B4B4B;
		font-size:30upx;
		text-align: center;
	}
	
	.article-content {
		color: #8B8B8B;
		font-size: 24upx;
		padding: 24upx 0;
	}
	
	.label-row {
		display: flex;
		flex-direction: row;
	}
	
	.label {
		color: #FFFFFF;
		font-size: 24upx;
		border-radius: 24upx;
		padding: 3upx 26upx;
		margin-right: 20upx;
	}
</style>
